package com.shzu.jwc.ty.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.bean.UserTeacherInfo;
import com.shzu.jwc.ty.bean.UserTeacherInfoExample;
import com.shzu.jwc.ty.common.MD5Util;
import com.shzu.jwc.ty.dao.UserTeacherInfoMapper;

@Service
public class UserTeacherInfoservice {

	@Autowired
	UserTeacherInfoMapper mapper;
	
	public List<UserTeacherInfo> serach(String userTeacherInfoName)
	{
		UserTeacherInfoExample example=new UserTeacherInfoExample();
		UserTeacherInfoExample.Criteria criteria=example.createCriteria();
		criteria.andUserTeacherInfoNameLike("%"+userTeacherInfoName+"%");
		return mapper.selectByExample(example);
	}
	
	public List<UserTeacherInfo> getteacher(){
		return mapper.selectByExample(null);
	}
	
	public Integer isextis(String userTeacherInfoNum) {
		UserTeacherInfoExample example=new UserTeacherInfoExample();
		UserTeacherInfoExample.Criteria criteria=example.createCriteria();
		criteria.andUserTeacherInfoNumEqualTo(userTeacherInfoNum);
		return (int) mapper.countByExample(example);
	}
	
	public Integer repass(Integer id) {
		String num=mapper.selectByPrimaryKey(id).getUserTeacherInfoNum();
		UserTeacherInfo userTeacherInfo=new UserTeacherInfo();
		userTeacherInfo.setUserTeacherInfoId(id);
		userTeacherInfo.setUserTeacherInfoPassword(MD5Util.encrypt(num));
		return mapper.updateByPrimaryKeySelective(userTeacherInfo);
	}
	
	public Integer insert(UserTeacherInfo userTeacherInfo) {
		return mapper.insertSelective(userTeacherInfo);
	}
	
	public Integer update(UserTeacherInfo userTeacherInfo) {
		return mapper.updateByPrimaryKeySelective(userTeacherInfo);
	}
	
	public Integer delete(Integer userTeacherInfoId) {
		return mapper.deleteByPrimaryKey(userTeacherInfoId);
	}
	
	public UserTeacherInfo getone(Integer userTeacherInfoId) {
		return mapper.selectByPrimaryKey(userTeacherInfoId);
	}
}
